package com.example.fbi_text.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SearchView;
import android.widget.TextView;

import com.example.fbi_text.Acitivity.SettingsActivity;
import com.example.fbi_text.R;

public class HeaderView extends RelativeLayout {

private TextView mHeaderBack;
private SearchView mSearchView;
private TextView mheader_title;
private Button mbutton_back;

private ImageView mImageView;

    public HeaderView(Context context) {
        super(context);
        initView();
    }

    public HeaderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }


    @SuppressLint("WrongViewCast")
    private  void  initView(){
        LayoutInflater.from(getContext()).inflate(R.layout.header_view,this,true);
        mHeaderBack = findViewById(R.id.header_back);
        mSearchView = findViewById(R.id.header_search);
        mImageView = findViewById(R.id.header_setting);
        mheader_title = findViewById(R.id.header_title);
        // 设置设置按钮的点击事件
        mImageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getContext(), SettingsActivity.class);
                getContext().startActivity(intent);
            }
        });
    }

    public  void setTitle(String title){
        if (mheader_title != null && !TextUtils.isEmpty(title)){
            mheader_title.setText(title);
        }
    }
    public void setTitleVisibility(int visibility){
        mheader_title.setVisibility(visibility);
    }
    public void setSerchViewVisibility(int visibility){
        mSearchView.setVisibility(visibility);
    }

    public  void setImageVisibility(int visibility){
        mImageView.setVisibility(visibility);
    }
    public  void setmHeaderBackVisibility(int visibility){
        mHeaderBack.setVisibility(visibility);
    }

    public void setmHeaderBackClickListener(OnClickListener listener){
        mHeaderBack.setOnClickListener(listener);
    }
    public void setImageViewClickListener(OnClickListener listener){
        mImageView.setOnClickListener(listener);
    }
    // 添加搜索监听方法
    public void setOnSearchListener(SearchView.OnQueryTextListener listener) {
        mSearchView.setOnQueryTextListener(listener);
    }

}
